package org.tis.tools.abf.module.sys.controller;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.tis.tools.abf.module.sys.entity.SysChannelCtl;
import org.tis.tools.abf.module.sys.service.ISysChannelCtlService;
import org.tis.tools.core.web.controller.BaseController;
import org.tis.tools.core.web.vo.SmartPage;
import org.tis.tools.model.common.ResultVO;
import org.tis.tools.model.log.enums.OperateType;
import org.tis.tools.starter.operatelog.annotation.OperateLog;

import javax.validation.constraints.NotBlank;

/**
 * sysChannelCtl的Controller类
 * 
 * @author Auto Generate Tools
 * @date 2018/04/23
 */
@RestController
@RequestMapping("/sysChannelCtl")
@Slf4j
public class SysChannelCtlController extends BaseController<SysChannelCtl>  {

    @Autowired
    private ISysChannelCtlService sysChannelCtlService;

    @ApiOperation(value = "新增渠道参数控制",notes = "传入SysChannelCtl类作为参数")
    @OperateLog(type = OperateType.ADD,desc = "新增渠道参数控制")
    @PostMapping
    public ResultVO add(@RequestBody @Validated @ApiParam(value = "SysChannelCtl",name = "传入的SysChannelCtl类", required = true) SysChannelCtl sysChannelCtl) {
        sysChannelCtlService.insert(sysChannelCtl);
        return ResultVO.success("新增成功！");
    }

    @ApiOperation(value = "修改渠道参数控制",notes = "传入SysChannelCtl类作为参数")
    @OperateLog(type = OperateType.UPDATE,desc = "修改渠道参数控制")
    @PutMapping
    public ResultVO update(@RequestBody @Validated @ApiParam(value = "SysChannelCtl",name = "传入的SysChannelCtl类", required = true) SysChannelCtl sysChannelCtl) {
        SysChannelCtl sysChannelCtlQue = sysChannelCtlService.selectById(SysChannelCtl.COLUMN_GUID);
        if (sysChannelCtlQue == null) {
            return ResultVO.error("404", "找不到对应记录或已经被删除！");
        }
        sysChannelCtlService.updateById(sysChannelCtl);
        return ResultVO.success("修改成功！",sysChannelCtl);
    }

    @ApiOperation(value = "删除渠道参数控制",notes = "传入渠道参数控制GUID作为参数")
    @OperateLog(type = OperateType.DELETE,desc = "删除渠道参数控制")
    @DeleteMapping("/{id}")
    public ResultVO delete(@PathVariable @NotBlank(message = "id不能为空") @ApiParam(value = "id",name = "渠道参数控制GUID", required = true) String id) {
        SysChannelCtl sysChannelCtl = sysChannelCtlService.selectById(id);
        if (sysChannelCtl == null) {
            return ResultVO.error("404", "找不到对应记录或已经被删除！");
        }
        sysChannelCtlService.deleteById(id);
        return ResultVO.success("删除成功");
    }


    @ApiOperation(value = "根据GUID查询渠道参数控制",notes = "传入渠道参数控制GUID作为参数")
    @GetMapping("/{id}")
    public ResultVO detail(@PathVariable @NotBlank(message = "id不能为空") @ApiParam(value = "id",name = "渠道参数控制GUID", required = true) String id) {
        SysChannelCtl sysChannelCtl = sysChannelCtlService.selectById(id);
        if (sysChannelCtl == null) {
            return ResultVO.error("404", "找不到对应记录或已经被删除！");
        }
        return ResultVO.success("查询成功", sysChannelCtl);
    }


    @ApiOperation(value = "分页查询渠道参数控制",notes = "传入分页信息作为参数")
    @PostMapping("/list")
    public ResultVO list(@RequestBody @Validated @ApiParam(value = "page",name = "分页信息", required = true) SmartPage<SysChannelCtl> page) {
        return  ResultVO.success("查询成功", sysChannelCtlService.selectPage(page.getPageObj(), page.getConditionWrapper()));
    }
}

